package com.czy.owner.ui.store.storeviewholder;


import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.StoreActivityModel;
import com.czy.owner.utils.TimeUtils;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;


/**
 * Created wangyang on 2016/9/21.
 */
public class StoreTvAndImgViewHolder extends BaseViewHolder<StoreActivityModel.StoreList> {
    private TextView tv_store_title;
    private TextView tv_store_time;
    private ImageView img_store_picture;
    private TextView tv_store_describe;
    private Context ctx;

    public StoreTvAndImgViewHolder(ViewGroup parent, Context ctx) {
        super(parent, R.layout.item_store);
        tv_store_title = $(R.id.tv_store_title);
        tv_store_time = $(R.id.tv_store_time);
        img_store_picture = $(R.id.img_store_picture);
        tv_store_describe = $(R.id.tv_store_describe);
        this.ctx=ctx;
    }

    @Override
    public void setData(StoreActivityModel.StoreList model) {
        try{
            tv_store_title.setText(model.getTitle());
            String time = TimeUtils.formatTimeDifference2(Long.parseLong(model.getCreateTime()));
            tv_store_time.setText(time);
            tv_store_describe.setText(model.getContent());
            loadPic(model);
        }catch (Exception e){

        }


    }

    private void loadPic(StoreActivityModel.StoreList model) {
        try {
        if (model.getResList() != null) {
                for (int i = 0; i < model.getResList().size(); i++) {
                    if (model.getResList().get(i).getResType().equals("pic")) {
                        GlideUtils.loadImage(ctx, model.getResList().get(i).getThumbnailUrl(), img_store_picture, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                            @Override
                            public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                            }

                            @Override
                            public void onLoadingError(String source, Exception e) {

                            }
                        },R.mipmap.default_banner,R.mipmap.default_banner);
                        return;
                    }
                }
            }

        }catch (Exception e) {

        }
    }
}
